package com.boyu.backend;

import com.boyu.common.BaseController;
import com.boyu.common.model.User;
import com.jfinal.plugin.activerecord.Page;
import org.joda.time.DateTime;

/**
 * IndexController
 */
public class _UserController extends BaseController {

	public void index() {
		int pageNo = getParaToInt(PAGE_NO,1);
		Page<User> userPage = userService.getUserPage(pageNo);
		setAttr("userPage",userPage);
		setAttr(PAGE_NO,pageNo);
		render(INDEX_HTML);
	}
	public void edit() {
		long id = getParaToLong(ID);
		User byId = User.dao.findById(id);
		setAttr("user", byId);
		render(EDIT_HTML);
	}

	public void save() {
		User model = getModel(User.class, "");
		if (model.getId() != null) {
			model.update();
		} else {
			model.setCreateTime(DateTime.now().toDate());
			model.save();
		}
		redirect(INDEX);
	}
	public void add() {
		render(ADD_HTML);
	}
}





